<?php

namespace App\Http\Controllers\Admin;

use App\Models\Orm\Banner;
use App\Models\Orm\Candy;
use App\Models\Orm\Grade;
use App\Models\Orm\Market;
use App\Models\Orm\AwAuditRecord;
use App\Models\Orm\CooperativeCompany;
use App\Models\Orm\Pay;
use App\Models\Orm\Sconfig;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

/**
 * 产品模块控制器
 *
 * Class ProductController
 * @package App\Http\Controllers\Admin
 */
class SconfigController extends Controller
{
    /**
     * 产品列表(展示页)
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $user = auth('admin')->user();

        $data = Sconfig::orderby('id', SORT_DESC)->get();
        return view('admin.config.index', compact('data'));

    }

    public function create(Request $request)
    {
        $user = auth('admin')->user();

        if ($request->isMethod('post')) {

            $request->flash();

            $insert_data = $request->except(['_token', 's']);


            $insert_data['created_at'] = date('Y-m-d H:i:s');
            $insert_data['updated_at'] = date('Y-m-d H:i:s');
//            dd($insert_data);
            Sconfig::create($insert_data);
            return redirect('/admin/config/index')->with(['success' => '您的申请已提交,请耐心等等待审核']);
        }

        $data = new Pay();

        return view('admin.config.create', compact('data'));
    }




    public function edit(Request $request, $id)
    {
        // 当前用户
        $user = auth('admin')->user();

        // 产品信息
        $product = Sconfig::find($id);

        if (!$product) {
            return back()->withErrors('未找到产品');
        }

        // post请求、提交表单
        if ($request->isMethod('post')) {

            $request->flash();

            $update_data = $request->except(['_token','s']);

            // 修改时间
            $update_data['updated_at'] = date('Y-m-d H:i:s');

            // 更改产品表
            $product->update($update_data);

            return redirect('/admin/config')->with(['success' => '修改成功']);
        }

        $data = $product;



        return view('admin.config.edit', compact('data'));
    }





}